package com.five.api.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.api.dao.CommentMapper;
import com.five.api.service.CommentService;
import com.five.entity.Comment;
import com.five.qo.ArticleCommentQO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 博客评论表 服务实现类
 * </p>
 *
 * @author star
 * @since 2021-06-16
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Override
    public List<ArticleCommentQO> selectCommentByUserId(Long userId) {
        List<ArticleCommentQO> articleComments = baseMapper.selectCommentByUserId(userId);
        return articleComments;
    }
    @Override
    public Page<Comment> getCommentsByArticleIdWithPage(Long articleId, Long current) {
        Page<Comment> page = new Page<>();
        page.setCurrent(current);
        page.setSize(5);
        List<Comment> comments = baseMapper.getCommentsByArticleIdWithPage(articleId, page);
        page.setRecords(comments);
        return page;
    }

    @Override
    public int deleteComment(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int insertComment(Comment comment) {
        return baseMapper.insert(comment);
    }
}
